clear all
set more off
set matsize 2000

*input folder path      
global filepath "D:\Dropbox\NREGA Aggregate\shared NREGA lights\replication files"

	  
cd "$filepath\raw data and cleaning"


*combine annual data
use "NREGA_data2006.dta", clear

forvalues year=2007/2013 {
merge 1:1 sno using "NREGA_data`year'.dta", nogen
}



*Manisha's correct spelling differences by hand
rename statename state_name
replace state_name =subinstr(state_name," ","",.)
rename districtname district_name
replace district_name =subinstr(district_name," ","",.)
replace district_name = upper(district_name)

 
replace 		state_name	=	"JAMMU&KASHMIR"			if 		state_name		==	"JAMMUANDKASHMIR"
replace 		state_name	=	"ORISSA"				if 		state_name		==	"ODISHA"
replace 		state_name	=	"PONDICHERRY"			if 		state_name		==	"PUDUCHERRY"
replace 		state_name	=	"D&NHAVELI"				if 		state_name		==	"DADRA&NAGARHAVELI"
replace 		state_name	=	"A&NISLANDS"			if 		state_name		==	"ANDOMANANDNICOBAR"
										
replace 		district_name 	=	"PAPUMPARE"	 		if 		district_name	==	"PAPUMPERA"
replace 		district_name 	=	"AURANAGABAD"		if 		district_name	==	"AURANAGABAD"
replace 		district_name 	=	"PURBACHAMPARAN"	if 		district_name	==	"PURBICHAMPARAN"
replace 		district_name 	=	"KORIYA"			if 		district_name	==	"KOREA"
replace 		district_name 	=	"RAJNANDGAON"		if 		district_name	==	"RAJNANDAGON"
replace 		district_name 	=	"DADRA&NAGARHAVELI"	if 		district_name	==	"DADARNAGARANDHAVELI"
replace 		district_name 	=	"AHMADABAD"			if 		district_name	==	"AHMEDABAD"
replace 		district_name 	=	"THEDANGS"			if 		district_name	==	"DANG"
replace 		district_name 	=	"KACHCHH"			if 		district_name	==	"KUTCHCHH"
replace 		district_name 	=	"LAHUL&SPITI"		if 		district_name	==	"LAHAUL&SPITI"
replace 		district_name 	=	"PASHCHIMISINGHBHUM"	if 		district_name	==	"WESTSINGHBHUM"
replace 		district_name 	=	"PURBISINGHBHUM"	if 		district_name	==	"EASTSINGHBUM"
replace 		district_name 	=	"SARAIKELLA"		if 		district_name	==	"SARAIKELAKHARSAWAN"
replace 		district_name 	=	"DHARWAD"			if 		district_name	==	"DHARWAR"
replace 		district_name 	=	"KASARAGOD"			if 		district_name	==	"KASARGOD"
replace 		district_name 	=	"THRISSUR"			if 		district_name	==	"THIRUSSUR"
replace 		district_name 	=	"NEEMUCH"			if 		district_name	==	"NIMACH"
replace 		district_name 	=	"GONDIYA"			if 		district_name	==	"GONDIA"
replace 		district_name 	=	"MAMIT"				if 		district_name	==	"MAMIT(AIZ-W)"
replace 		district_name 	=	"SERCHHIP"			if 		district_name	==	"SERCHIPP(AIZ-S)"
replace 		district_name 	=	"FIROZPUR"			if 		district_name	==	"FEROZEPUR"
replace 		district_name 	=	"GANGANAGAR"		if 		district_name	==	"SRIGANGANAGAR"
replace 		district_name 	=	"KANNIYAKUMARI"		if 		district_name	==	"KANYAKUMARI"
replace 		district_name 	=	"THIRUVARUR"		if 		district_name	==	"TIRUVARUR"
replace 		district_name 	=	"THOOTHUKKUDI"		if 		district_name	==	"TUTICORIN"
replace 		district_name 	=	"VIRUDHUNAGAR"		if 		district_name	==	"VIRUDUNAGAR"
replace 		district_name 	=	"GARHWAL"			if 		district_name	==	"PAURIGARHWAL"
replace 		district_name 	=	"UDHAMSINGHNAGAR"	if 		district_name	==	"UDAMSINGHNAGAR"
replace 		district_name 	=	"BAGHPAT"			if 		district_name	==	"BAGPAT"
replace 		district_name 	=	"BIJNOR"			if 		district_name	==	"BIJNOUR"
replace 		district_name 	=	"GAUTAMBUDDHANAGAR"	if 		district_name	==	"GAUTAMBUDHNAGAR"
replace 		district_name 	=	"GHAZIPUR"			if 		district_name	==	"GAZIPUR"
replace 		district_name 	=	"SANTKABIRNAGAR"	if 		district_name	==	"SANTKABEERNAGAR"
replace 		district_name 	=	"SANTRAVIDASNAGARBHDOHI"		if 		district_name	==	"SANTRAVIDASNAGAR"
replace 		district_name 	=	"SHRAWASTI"			if 		district_name	==	"SHRAVASTI"
replace 		district_name 	=	"NORTHTWENTYFOURPARG"		if 		district_name	==	"24PARGANAS(NORTH)"
replace 		district_name 	=	"SOUTHTWENTYFOURPARG"		if 		district_name	==	"24PARGANASSOUTH"
replace 		district_name 	=	"KOCHBIHAR"			if 		district_name	==	"COOCHBEHAR"
replace 		district_name 	=	"DARJILING"			if 		district_name	==	"DARJEELINGGORKHAHILLCOUNCIL(DGHC)"
replace 		district_name 	=	"DAKSHINDINAJPUR"	if 		district_name	==	"DINAJPURDAKSHIN"
replace 		district_name 	=	"HUGLI"				if 		district_name	==	"HOOGHLY"
replace 		district_name 	=	"HAORA"				if 		district_name	==	"HOWRAH"
replace 		district_name 	=	"PURULIYA"			if 		district_name	==	"PURULIA"
replace 		district_name 	=	"UTTARDINAJPUR"		if 		district_name	==	"DINAJPURUTTAR"
replace 		district_name 	=	"MAHESANA"			if 		district_name	==	"MEHSANA"
replace 		district_name 	=	"HISAR"				if 		district_name	==	"HISSAR"
replace 		district_name 	=	"BARAMULA"			if 		district_name	==	"BARAMULLA"
replace 		district_name 	=	"LEH(LADAKH)"		if 		district_name	==	"LEH"
replace 		district_name 	=	"PUNCH"				if 		district_name	==	"POONCH"
replace 		district_name 	=	"RAJAURI"			if 		district_name	==	"RAJOURI"
replace 		district_name 	=	"KODARMA"			if 		district_name	==	"KODERMA"
replace 		district_name 	=	"PAKAUR"			if 		district_name	==	"PAKUR"
replace 		district_name 	=	"SAHIBGANJ"			if 		district_name	==	"SAHEBGANJ"
replace 		district_name 	=	"SINDEGA"			if 		district_name	==	"SIMDEGA"
replace 		district_name 	=	"BAGALKOT"			if 		district_name	==	"BAGALKOTE"
replace 		district_name 	=	"AHMADNAGAR"		if 		district_name	==	"AHMEDNAGAR"
replace 		district_name 	=	"BID"				if 		district_name	==	"BEED"
replace 		district_name 	=	"BULDANA"			if 		district_name	==	"BULDHANA"
replace 		district_name 	=	"RAIGARH"			if 		district_name	==	"RAIGAD"
replace 		district_name 	=	"ANUGUL"			if 		district_name	==	"ANGUL"
replace 		district_name 	=	"BALANGIR"			if 		district_name	==	"BOLANGIR"
replace 		district_name 	=	"BAUDH"				if 		district_name	==	"BOUDH"
replace 		district_name 	=	"DEBAGARH"			if 		district_name	==	"DEOGARH"
replace 		district_name 	=	"JAGATSINGHAPUR"	if 		district_name	==	"JAGATSINGHPUR"
replace 		district_name 	=	"JAJAPUR"			if 		district_name	==	"JAJPUR"
replace 		district_name 	=	"KHORDHA"			if 		district_name	==	"KHURDA"
replace 		district_name 	=	"SONAPUR"			if 		district_name	==	"SONEPUR"
replace 		district_name 	=	"BATHINDA"			if 		district_name	==	"BHATINDA"
replace 		district_name 	=	"MUKTSAR"			if 		district_name	==	"MUKATSAR"
replace 		district_name 	=	"CHITTAURGARH"		if 		district_name	==	"CHITTORGARH"
replace 		district_name 	=	"DHAULPUR"			if 		district_name	==	"DHOLPUR"
replace 		district_name 	=	"JALOR"				if 		district_name	==	"JALORE"
replace 		district_name 	=	"JHUNJHUNUN"		if 		district_name	==	"JHUNJHUNU"
replace 		district_name 	=	"KANCHEEPURAM"		if 		district_name	==	"KANCHIPURAM"
replace 		district_name 	=	"PUDUKKOTTAI"		if 		district_name	==	"PUDUKOTTAI"
replace 		district_name 	=	"SIVAGANGA"			if 		district_name	==	"SIVAGANGAI"
replace 		district_name 	=	"TIRUCHIRAPPALLI"	if 		district_name	==	"TIRUCHIRAPALLI"
replace 		district_name 	=	"VILUPPURAM"		if 		district_name	==	"VILLUPURAM"
replace 		district_name 	=	"HARDWAR"			if 		district_name	==	"HARIDWAR"
replace 		district_name 	=	"AURAIYA"			if 		district_name	==	"AURRIYA"
replace 		district_name 	=	"MAHRAJGANJ"		if 		district_name	==	"MAHARAJGANJ"


*Drop Daman/Diu
drop if sno==126 | sno==127


*nregs perpetually on
forvalues i=2007/2013{
replace nrega`i'=1 if nrega2006==1
}

forvalues i=2008/2013{
replace nrega`i'=1 if nrega2007==1
}

forvalues i=2009/2013{
replace nrega`i'=1 if nrega2008==1
}

forvalues i=20010/2013{
replace nrega`i'=1 if nrega2009==1
}

forvalues i=2011/2013{
replace nrega`i'=1 if nrega2010==1
}

forvalues i=2012/2013{
replace nrega`i'=1 if nrega2011==1
}

replace nrega2013=1 if nrega2012==1


*pre-period; no NREGS
forvalues i=1992/2005{
gen nrega`i' = 0
}



*waves
gen nr06 = nrega2006
gen nr07 = nrega2007-nrega2006
gen nr08 = 1 if nr06==0 & nr07==0
	replace nr08=0 if nr06==1
	replace nr08=0 if nr07==1

*save 
save "nrega_wide.dta", replace


